package com.hosp.controller.v1;

import java.util.Arrays;
import java.util.List;

import com.github.pagehelper.PageInfo;
import com.hosp.bean.Chargeproject;
import com.hosp.service.ChargeProjectervice;
import com.hosp.vo.PageRequestVO;
import com.hosp.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 收费项目 API
 *
 * @author bing.zhang06@hand-china.com 2021/10/16 11:09
 **/
@Slf4j
@RestController
@RequestMapping("/charge-project")
public class ChargeProjectController {
    @Autowired
    private ChargeProjectervice chargeProjectervice;

    /**
     * 查询列表
     *
     * @param chargeproject 查询条件
     * @param pageRequest   分页条件
     * @return 响应
     */
    @GetMapping("/list")
    public ResultVO<Chargeproject> list(Chargeproject chargeproject, PageRequestVO pageRequest) {
        log.debug("input is {}.", chargeproject);
        PageInfo<Chargeproject> pageInfo = chargeProjectervice.list(chargeproject, pageRequest);
        return new ResultVO<>(pageInfo);
    }

    /**
     * 查询集合
     *
     * @param chargeproject 查询条件
     * @return 响应
     */
    @GetMapping("/search")
    public ResultVO<Chargeproject> list(Chargeproject chargeproject) {
        log.debug("input is {}.", chargeproject);
        List<Chargeproject> list = chargeProjectervice.search(chargeproject);
        return new ResultVO<>(list);
    }

    /**
     * 主键查询
     *
     * @param chapId 查询条件
     * @return 响应
     */
    @GetMapping("/{chapId}")
    public ResultVO<Chargeproject> selectById(@PathVariable("chapId") Integer chapId) {
        Chargeproject chargeproject = chargeProjectervice.selectById(chapId);
        return new ResultVO<>(chargeproject);
    }

    /**
     * 删除元素
     *
     * @param chapId 删除主键
     * @return 响应
     */
    @PostMapping("/delete")
    public ResultVO<String> deleteById(Integer chapId) {
        boolean flag = chargeProjectervice.delete(Arrays.asList(chapId));

        if (flag) {
            return new ResultVO<>(200, "删除成功");
        } else {
            return new ResultVO<>(500, "删除失败");
        }
    }

    /**
     * 保存
     *
     * @param chargeproject 保存对象
     * @return 响应
     */
    @PostMapping("/save")
    public ResultVO<String> save(Chargeproject chargeproject) {
        log.debug("Chargeproject is {}.", chargeproject);

        boolean flag = chargeProjectervice.save(chargeproject);

        if (flag) {
            return new ResultVO<>(200, "保存成功");
        } else {
            return new ResultVO<>(500, "保存失败");
        }
    }

    @GetMapping("/check")
    public ResultVO<String> check(String chapName) {
        boolean flag = chargeProjectervice.check(chapName);
        if (flag) {
            return new ResultVO<>(200, null);
        } else {
            return new ResultVO<>(500, null);
        }
    }
}
